<?php
include( "admin/now5_header.php" );
$percent = 0;
$lostwin = array();
$betcount = array();
$totalamount = array();
$list = array("", "", "", "", "", "", "", "", "", "");
$bettype = 29;
$rowNum = 20;
$colNum = 5;
$tot = $rowNum * $colNum;
$totalamount[$bettype] = 0;
$betcount[$bettype] = 0;
$betTypeStr = "";
switch ($bettype)
{
    case 9 :
        $betTypeStr = "bettype IN ( 9,33)";
        break;
    case 10 :
        $betTypeStr = "bettype IN (10,32)";
        break;
    default :
        $betTypeStr = "bettype=" . $bettype;
        break;
}
$sql = " sum(totalAmt) as totalAmt FROM (\r\n  Select line_nums,(unitmoney*upercent/100) as totalAmt\r\n  from bet where {$betTypeStr} and lotto_id={$lotto_id} and rame in (0,9) \r\n  UNION ALL\r\n  Select line_nums,(unitmoney*percent255/100) as totalAmt\r\n  from bet2 where {$betTypeStr} and lotto_id={$lotto_id} and rame in (0,9) \r\n  UNION ALL\r\n  Select line_nums,(amount*-1) as totalAmt\r\n  from bet8 where {$betTypeStr} and lotto_id={$lotto_id} and rame in (0,9) \r\n  ) A";
$rs1 = getdb("SELECT " . $sql);
$rs2 = getdb("Select line_nums," . $sql . " GROUP BY line_nums Order by totalAmt desc LIMIT " . $tot);
$totalamount[$bettype] = round($rs1->f[0], 0);
if ($totalamount[$bettype] != 0)
{
    $col = 0;
    $recc = 0;
    while (!$rs2->eof)
    {
        $c = $rs2->f[0];
        $n = round($rs2->f[1], 0);
        if ($recc == 0)
        {
            $list[$col] = "<table border=0 width=88% cellspacing=0 cellpadding=0>";
        }
        if ($c != "" && $n != 0)
        {
            $list .= $col;
            $list .= $col;
            $list .= $col;
        }
        if ($rowNum - 1 <= $recc)
        {
            $list .= $col;
            ++$col;
            $recc = 0;
        }
        else
        {
            ++$recc;
        }
        $rs2->movenext();
    }
    if (0 < $recc && $recc < $rowNum - 1)
    {
        $list .= $col;
    }
}
$rs1->close();
$rs2->close();
$disk = $disk == 0 ? 1 : $disk;
$rs = getdb("select * from rate29 where lotto_id=" . $lotto_id . " and disk={$disk}");
if ($rs->eof)
{
    $ui->showErrorPage("<p class=error>系统目前维护中，请稍後！</p>");
    exit();
}
$rate_list = "";
$y = 0;
while ($y <= 4)
{
    $rate_list .= "<tr>";
    $x = 1;
    while ($x <= 10)
    {
        $num = d2($y * 10 + $x);
        if ($num == "50")
        {
            break;
        }
        $rate = $rs->f["r" . $num];
        $ball = "";
        if (array_search(intval($num), $g_red_po) !== false)
        {
            $ball = "background='image/red.gif'";
        }
        else if (array_search(intval($num), $g_blue_po) !== false)
        {
            $ball = "background='image/blue.gif'";
        }
        else
        {
            $ball = "background='image/green.gif'";
        }
        $rate_list .= "<td class='ball_td' align='middle' {$ball} bgColor='#c0d6eb' height='27' width='90'>" . "<b>{$num}</b></td><td bgColor='#e7ebef' nowrap>" . "&nbsp;<input type='button' onclick=ratediff(29,{$num},-0.01) value='-' class='btnmin'>&nbsp;" . "{$rate}" . "&nbsp;<input type='button' onclick=ratediff(29,{$num},0.01) value='+' class='btnplus'>&nbsp;" . "</td>";
        ++$x;
    }
    $rate_list .= "</tr>";
    ++$y;
}
$tpl->set("rate_list", $rate_list);
$i = 0;
while ($i < 6)
{
    $tpl->set("list" . $i, $list[$i]);
    ++$i;
}
$btn0 = getvar("btn0");
$btn1 = getvar("btn1");
if ($btn0 == "")
{
    $btn0 = 11;
}
if ($btn1 == "")
{
    $btn1 = 0.01;
}
$tpl->set("btn0", $btn0);
$tpl->set("btn1", $btn1);
$tpl->set("totall", "显示排行前 <b>" . $tot . "</b> 笔，合计金额：<b>" . $totalamount[29] . "</b>");
$tpl->load("main", "now5_29.htm");
$tpl->set("jslang", $g_conf['language']);
$tpl->set("lotto_id", $lotto_id);
$tpl->show("main");
$ui->footer();
?>